using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VPJMASSNA
    {
        public DataRow Convert2PJMASSNA(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryPJMASSNA(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["PMAMANDANT"] = " ".PadRight(2 ); 
         dwReturn["PMAPROJNR"] = " ".PadRight(5 ); 
         dwReturn["PMALFDNR"] = " ".PadRight(4 ); 
         dwReturn["PMAMASSNAHME"] = " ".PadRight(10 ); 
         dwReturn["PMABEZ"] = " ".PadRight(50 ); 
         dwReturn["PMAKOSTENEIN"] = " ".PadRight(0 ); 
         dwReturn["PMAKOSTENJEKD"] = " ".PadRight(0 ); 
         dwReturn["PMAANZTAET"] = " ".PadRight(0 ); 
         dwReturn["PMAANZTAETUEBW"] = " ".PadRight(0 ); 
         dwReturn["PMAANZTAETERL"] = " ".PadRight(0 ); 
         dwReturn["PMAUEBWKENNZ"] = " ".PadRight(1 ); 
         dwReturn["PMAERMVERANTW"] = " ".PadRight(1 ); 
         dwReturn["PMASTDVERANTW"] = " ".PadRight(8 ); 
         dwReturn["PMATERMIN"] = " ".PadRight(0 ); 
         dwReturn["PMANEUBEN"] = " ".PadRight(8 ); 
         dwReturn["PMANEUDAT"] = " ".PadRight(0 ); 
         dwReturn["PMAAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["PMAAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["PMAAENDZL"] = " ".PadRight(0 ); 
         dwReturn["PMAFILLER"] = " ".PadRight(35 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapPJMASSNA(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SavePJMASSNA(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryPJMASSNA(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapPJMASSNA(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertPJMASSNA(dwLocal, ITXDBVERSION);
            }
            UpdatePJMASSNA(dwLocal);
        }
        public void InsertPJMASSNA(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO PJMASSNA(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryPJMASSNA(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM PJMASSNA WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM PJMASSNA  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "PJMASSNA";
            Return = Result;
            return Return;
        }
        public void DeletePJMASSNA(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM PJMASSNA   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdatePJMASSNA(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE PJMASSNA SET "
                    +"PMAMANDANT= :PMAMANDANT,"
                    +"PMAPROJNR= :PMAPROJNR,"
                    +"PMALFDNR= :PMALFDNR,"
                    +"PMAMASSNAHME= :PMAMASSNAHME,"
                    +"PMABEZ= :PMABEZ,"
                    +"PMAKOSTENEIN= :PMAKOSTENEIN,"
                    +"PMAKOSTENJEKD= :PMAKOSTENJEKD,"
                    +"PMAANZTAET= :PMAANZTAET,"
                    +"PMAANZTAETUEBW= :PMAANZTAETUEBW,"
                    +"PMAANZTAETERL= :PMAANZTAETERL,"
                    +"PMAUEBWKENNZ= :PMAUEBWKENNZ,"
                    +"PMAERMVERANTW= :PMAERMVERANTW,"
                    +"PMASTDVERANTW= :PMASTDVERANTW,"
                    +"PMATERMIN= :PMATERMIN,"
                    +"PMANEUBEN= :PMANEUBEN,"
                    +"PMANEUDAT= :PMANEUDAT,"
                    +"PMAAENDBEN= :PMAAENDBEN,"
                    +"PMAAENDDAT= :PMAAENDDAT,"
                    +"PMAAENDZL= :PMAAENDZL,"
                    +"PMAFILLER= :PMAFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("PMAMANDANT", OracleType.NVarChar).Value = dwData["PMAMANDANT"].ToString(); 
          or1.Parameters.Add("PMAPROJNR", OracleType.NVarChar).Value = dwData["PMAPROJNR"].ToString(); 
          or1.Parameters.Add("PMALFDNR", OracleType.NVarChar).Value = dwData["PMALFDNR"].ToString(); 
          or1.Parameters.Add("PMAMASSNAHME", OracleType.NVarChar).Value = dwData["PMAMASSNAHME"].ToString(); 
          or1.Parameters.Add("PMABEZ", OracleType.NVarChar).Value = dwData["PMABEZ"].ToString(); 
          or1.Parameters.Add("PMAKOSTENEIN", OracleType.NVarChar).Value = dwData["PMAKOSTENEIN"].ToString(); 
          or1.Parameters.Add("PMAKOSTENJEKD", OracleType.NVarChar).Value = dwData["PMAKOSTENJEKD"].ToString(); 
          or1.Parameters.Add("PMAANZTAET", OracleType.NVarChar).Value = dwData["PMAANZTAET"].ToString(); 
          or1.Parameters.Add("PMAANZTAETUEBW", OracleType.NVarChar).Value = dwData["PMAANZTAETUEBW"].ToString(); 
          or1.Parameters.Add("PMAANZTAETERL", OracleType.NVarChar).Value = dwData["PMAANZTAETERL"].ToString(); 
          or1.Parameters.Add("PMAUEBWKENNZ", OracleType.NVarChar).Value = dwData["PMAUEBWKENNZ"].ToString(); 
          or1.Parameters.Add("PMAERMVERANTW", OracleType.NVarChar).Value = dwData["PMAERMVERANTW"].ToString(); 
          or1.Parameters.Add("PMASTDVERANTW", OracleType.NVarChar).Value = dwData["PMASTDVERANTW"].ToString(); 
          or1.Parameters.Add("PMATERMIN", OracleType.NVarChar).Value = dwData["PMATERMIN"].ToString(); 
          or1.Parameters.Add("PMANEUBEN", OracleType.NVarChar).Value = dwData["PMANEUBEN"].ToString(); 
          or1.Parameters.Add("PMANEUDAT", OracleType.NVarChar).Value = dwData["PMANEUDAT"].ToString(); 
          or1.Parameters.Add("PMAAENDBEN", OracleType.NVarChar).Value = dwData["PMAAENDBEN"].ToString(); 
          or1.Parameters.Add("PMAAENDDAT", OracleType.NVarChar).Value = dwData["PMAAENDDAT"].ToString(); 
          or1.Parameters.Add("PMAAENDZL", OracleType.NVarChar).Value = dwData["PMAAENDZL"].ToString(); 
          or1.Parameters.Add("PMAFILLER", OracleType.NVarChar).Value = dwData["PMAFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
